package Chapter2;

public class MyLinkedList {
	public MyLinkedListNode Head;
	
	public void add(int data)
	{
		MyLinkedListNode end = new MyLinkedListNode(data);
		if(Head == null){
			Head = end;
		}else{
			MyLinkedListNode n = Head;
			while(n.Next != null){
				n = n.Next;
			}
			n.Next = end;
		}
	}
	
	public void delete(int data)
	{
		MyLinkedListNode n = Head;
		if(Head.value == data){
			Head = Head.Next;
			return;
		}else{
			while(n.Next != null)
			{
				if(n.Next.value == data){
					n.Next = n.Next.Next;
					return;
				}
				n = n.Next;
			}
		}
		return;
	}
	
	public boolean isNull()
	{
		return (Head == null);
	}
	
	public void checkResult()
	{
		if(isNull()) return;
		MyLinkedListNode n = Head;
		System.out.println(n.value);
		while(n.Next != null)
		{
			n = n.Next;
			System.out.println(n.value);
		}
	}
//	public static void main(String args[])
//	{
//		MyLinkedList mll = new MyLinkedList();
//		mll.add(1);
//		mll.add(2);
//		mll.add(3);
//		mll.delete(3);
//		mll.checkResult();
//	}
}
